package com.pactera.miyuangroup.controller.web;

import com.pactera.miyuangroup.service.OrganizationStructureService;
import com.pactera.miyuangroup.vo.convertor.OrganizationConvert;
import com.pactera.miyuangroup.vo.request.VoidRequest;
import com.pactera.miyuangroup.vo.response.ResultModel;
import com.pactera.miyuangroup.vo.response.ResultStatusCode;
import com.pactera.miyuangroup.vo.response.VoidResponse;
import com.pactera.miyuangroup.vo.response.web.OrganizationRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 组织结构
 *
 * @author Wangwu
 * @create 2018-04-20 上午10:15
 **/
@Api(description = "组织结构接口")
@RestController
@RequestMapping("org")
public class OrganizationController {
    @Autowired
    private OrganizationStructureService organizationStructureService;

    /**
     * 获取组织结构
     *
     * @return
     */
    @ApiOperation(value = "组织结构查询", notes = "查询组织结构信息")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ResultModel<List<OrganizationRes>> getList(@RequestBody VoidRequest req) {
        List<OrganizationRes> org = organizationStructureService.getTreeOrgList();
        return ResultModel.ok(org);
    }


    @ApiOperation(value = "同步组织结构", notes = "同步组织结构")
    @RequestMapping(value = "/syncInfo", method = RequestMethod.GET)
    public ResultModel<VoidResponse> syncOrgInfo() {
        boolean flg = organizationStructureService.syncMiyuanOrgInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }
}
